<template>
  <div style="background: #fff">
    <div class="title">
      <div>{{ title }}</div>
    </div>
    <div style="padding: 1.875rem">
      <el-form :inline="true">
        <!-- <el-form-item label="">
          <el-input
            v-model="query.name"
            placeholder="订单号"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item label="选择状态">
          <el-select v-model="query.status" placeholder="请选择" clearable @change="getData(true)">
            <el-option
              v-for="item in status"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <!-- <el-button type="success" @click="getData(true)">查询</el-button> -->
          <!-- <el-button @click="reset">重置</el-button> -->
          <el-button type="primary" @click="cash" v-if="query.status==1">打款</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="data"
      stripe
      style="width: 100%; margin-bottom: 1.875rem"
      @selection-change="selectChange"
    >
      <el-table-column type="selection" width="55"  v-if="query.status==1" >
      </el-table-column>
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column label="会员昵称">
        <template slot-scope="scope">
          {{ scope.row.user.nick_name }}
        </template>
      </el-table-column>
      <el-table-column label="会员头像">
        <template slot-scope="scope">
          <el-image
            :src="
              cdn+scope.row.user.icon +
              '?imageView2/1/w/50/h/50/format/webp/q/75|imageslim'
            "
            style="width: 50px; height: 50px"
            :preview-src-list="[cdn+scope.row.user.big_icon]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="out_trade_no" label="流水号"></el-table-column>
      <el-table-column prop="price" label="金额"></el-table-column>

      <el-table-column prop="created_at" label="申请时间"></el-table-column>

      <el-table-column prop="handle_at" label="处理时间"></el-table-column>
      <el-table-column prop="pay_at" label="到账时间"></el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          {{ ["待打款", "到账中", "已到账"][scope.row.status - 1] }}
        </template>
      </el-table-column>

      <!-- <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="small" @click="showEdit(scope.row.id)">查看详情</el-button>
          <el-button type="error" size="small" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pages.currentPage"
      :page-size="pages.per_page"
      layout="total,prev, pager, next"
      :total="pages.total"
      style="text-align: center"
    >
    </el-pagination>
  </div>
</template>

<script>
import mixin from "../../js/mixin";

export default {
  name: "homePage",
  mixins: [mixin],
  data() {
    return {
      is_page: true,
      api_url: "user/cash",
      item: {},
      status: [
        {
          id: 1,
          name: "待打款",
        },
        {
          id: 2,
          name: "到账中",
        },
        {
          id: 3,
          name: "已到账",
        },
      ],
      query: {
          status:1
      },
    };
  },
  components: {},
  mounted() {},
  created() {
    this.title = this.$route.meta.title;
    this.init();
  },
  methods: {
    reset() {
      this.query = {};
      this.getData(true);
    },
    init() {
      this.getData();
    },

    cash() {
      let query = { select: this.select };
      if (query.select.length == 0) {
        this.$message({
          type: "error",
          message: "您尚未勾选",
        });
        return;
      }
      this.$confirm("此操作将无法撤回, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.global.httpRequest(this.api_url, query, "post").then((res) => {
            let { code } = res;
            if (code == 0) {
              this.getData(true);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },

    selectChange(e) {
      this.select = e.map((x) => {
        if (x.status == 1) {
          return x.id;
        }
      });
      console.log(this.select);
    },
  },
};
</script>

<style scoped>
</style>
